package com.itheima.util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;
import java.util.Map;

public class JwtUtil {
    private static String signKey = "itheima";
    private static Long expire = 43200000L;

    public static String getJwt( Map<String, Object> clams) {


        String jwt = Jwts.builder()
                .signWith(SignatureAlgorithm.HS256, signKey)//签名算法
                .setClaims(clams)//自定义载荷json格式(map集合就好)
                .setExpiration(new Date(System.currentTimeMillis()+expire))//设置令牌有效时间
                .compact();
       return jwt;
    }

    public static Map<String, Object> ParseTwt(String jwt){
        Map<String, Object> claims = Jwts.parser()
                .setSigningKey(signKey)
                .parseClaimsJws(jwt)
                .getBody();
        return claims;
    }
}
